﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;

namespace Torch_Common.Helpes
{
    public class Appsettings
    {
        static IConfiguration Configuration { get; set; }
        static string contentPath { get; set; }
        public Appsettings(string contentPath)
        {
            string Path = "appsettings.json";

            Configuration = new ConfigurationBuilder()
                            .SetBasePath(contentPath)
                            .Add(new JsonConfigurationSource
                            {
                                Path = Path,
                                Optional = false,
                                ReloadOnChange = true
                            })
                            .Build();
        }

        public Appsettings(IConfiguration configuration)
        {
            Configuration = configuration;
        }


        public static string app(params string[] sections)
        {
            try
            {
                if (sections.Any())
                {
                    var msg = Configuration[string.Join(":", sections)];
                    return msg;
                }
            }
            catch (Exception) { }
            return "";
        }

        public static List<T> app<T>(params string[] sections)
        {
            List<T> list = new List<T>();
            Configuration.Bind(string.Join(":", sections), list);
            return list;
        }


    }
}
